<template>
  <div class="pagination-wrapper">
    <div>
      <el-button plain size="small" @click="prev" v-if="topicIndex > 0">上一题</el-button>
    </div>
    <div>
      <template v-if="topicIndex + 1 >= topicSum">
        <el-button type="primary" size="small" @click="end">提交</el-button>
      </template>
      <el-button type="primary" size="small" @click="next" v-else>下一题</el-button>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  props: {
    submitBtnVisible: {
      type: Boolean,
      default: true
    }
  },
  computed: {
    ...mapState({
      topicSum: state => state.exercise.topic_sum,
      topicIndex: state => state.exercise.topic_index
    })
  },
  methods: {
    // 下一题
    next() {
      this.$emit('next')
    },
    // 上一题
    prev() {
      this.$emit('prev')
    },
    // 最后一题
    end() {
      this.$emit('end')
    }
  }
}
</script>

<style lang="scss" scoped>
.pagination-wrapper {
  border-top: 1px solid #f7f7f7;
  padding: 24px 20px;
  display: flex;
  justify-content: space-between;
  .el-button {
    width: 140px;
  }
}
</style>
